package com.sunu.service;

import com.sunu.dao.JobDao;
import com.sunu.dao.WorkerDao;
import com.sunu.dao.Worker_JobDao;
import com.sunu.entity.job.Job;
import com.sunu.entity.worker.Worker;
import com.sunu.entity.worker_job.Worker_Job;
import com.sunu.service.impl.DistributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by i on 2019/9/20.
 */
@Service
public class DistributeServiceImpl implements DistributeService {
    @Autowired
    private WorkerDao workerDao;
    @Autowired
    private JobDao jobDao;
    @Autowired
    private Worker_JobDao worker_jobDao;

    @Override
    public Worker getWorkerById(Integer workerId) {
        return workerDao.selectById(workerId);

    }

    @Override
    public List<Worker> getWorkerList() {
        return workerDao.queryAll();
    }

    @Override
    public List<Job> getJobList() {
        return jobDao.queryAllJob();
    }

    @Override
    public List<Worker_Job> getWorkerJobList() {
        return worker_jobDao.queryAllWorkerJob();
    }

    @Override
    public void addWorker(Worker worker) {
        workerDao.insertWorker(worker);

    }

    @Override
    public void addJob(Job job) {
        jobDao.insertJob(job);

    }

    @Override
    public void deleteJob(Integer JobId) {
        jobDao.deleteById(JobId);

    }

    @Override
    public void fireWorker(Integer WorkerId) {
        workerDao.deleteById(WorkerId);
    }

    @Override
    public void DistributeJob(String workerName, String jobName) {
        Worker worker = workerDao.selectByName(workerName);
        Job job = jobDao.selectByName(jobName);
        System.out.println(worker.toString());
        System.out.println(job.toString());
        Worker_Job worker_job = new Worker_Job(worker, job);
        System.out.println(worker_job.toString());
        worker_jobDao.insert(worker_job);
    }

    @Override
    public void deleteWorkerJob(Integer workerId, Integer jobId) {
        worker_jobDao.deleteByWorkerIdAndJobId(workerId, jobId);
    }

}
